package edu.zut.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 *
 */
@WebServlet(name = "SessionDemo2" ,value = "/session/demo2")
public class SessionDemo2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //通过请求获取session, 如果存在对应的session，直接使用，如果不存在，就创建
        HttpSession session = request.getSession();
        Object myName = session.getAttribute("myName");
        System.out.println("myName = " + myName);
        Object myAge = session.getAttribute("myAge");
        System.out.println("myAge = " + myAge);
        //session的无效化  注销
        session.invalidate();
    }
}
